package cn.stylefeng.guns.modular.User.controller;

import cn.stylefeng.guns.core.annotion.BusinessLog;
import cn.stylefeng.guns.core.enums.LogAnnotionOpTypeEnum;
import cn.stylefeng.guns.core.pojo.response.ResponseData;
import cn.stylefeng.guns.core.pojo.response.SuccessResponseData;
import cn.stylefeng.guns.modular.User.param.UserParam;
import cn.stylefeng.guns.modular.User.service.UserService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
public class UserController {

    @Resource
    private UserService userService;


    @GetMapping("/user/list")
    @BusinessLog(title = "user_waiter_增加_查询所有", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData list(UserParam userParam){
        return new SuccessResponseData(userService.list(userParam));
    }

    @PostMapping("/user/add")
    @BusinessLog(title = "user_waiter_增加", opType = LogAnnotionOpTypeEnum.ADD)
    public ResponseData add(@RequestBody @Validated(UserParam.add.class) UserParam userParam) {
        userService.add(userParam);
        return new SuccessResponseData();
    }

    @PostMapping("/user/delete")
    @BusinessLog(title = "user_waiter_删除", opType = LogAnnotionOpTypeEnum.DELETE)
    public ResponseData delete(@RequestBody @Validated(UserParam.delete.class) UserParam userParam) {
        userService.delete(userParam);
        return new SuccessResponseData();
    }

    @PostMapping("/user/edit")
    @BusinessLog(title = "user_waiter_编辑", opType = LogAnnotionOpTypeEnum.EDIT)
    public ResponseData edit(@RequestBody @Validated(UserParam.edit.class) UserParam userParam) {
        userService.edit(userParam);
        return new SuccessResponseData();
    }

    @GetMapping("/user/sort")
    @BusinessLog(title = "user_waiter_服务员分值排序", opType = LogAnnotionOpTypeEnum.QUERY)
    public ResponseData lookWaiterScoreSort(int pid,int day){

        return new SuccessResponseData(userService.lookWaiterScore(pid,day));
    }

    @PostMapping("/user/changeStatus")
    @BusinessLog(title = "user_waiter_修改状态", opType = LogAnnotionOpTypeEnum.CHANGE_STATUS)
    public ResponseData changeStatus(@RequestBody @Validated(UserParam.changeStatus.class) UserParam userParam) {
        userService.changeStatus(userParam);
        return new SuccessResponseData();
    }


}
